/*************************************************************************
	> File Name: P1890.cpp
	> Author: yufangze
	> Mail: 2224590123@qq.com
	> Created Time: 2025-01-03 15:57:33
 ************************************************************************/
#include <iostream>
using namespace std;

#define MAX_N 1000

int f[MAX_N + 5][MAX_N + 5];

int gcd(int a, int b) {
    return (b ? gcd(b, a % b) : a);
}

int main() {
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        scanf("%d", &f[i][i]);
    }
    for (int i = n - 1; i >= 1; i--) {
        for (int j = i + 1; j <= n; j++) {
            f[i][j] = gcd(f[i][i], f[i + 1][j]);
        }
    }
    for (int i = 1; i <= m; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        printf("%d\n", f[a][b]);
    }
    return 0;
}
